layui.use(['form','table'], function () {
    var form = layui.form,
        layer = layui.layer,
        $ = layui.$;
        table = layui.table
    //监听提交
    form.on('submit(save-btn)', function (data) {
        let url = ctx + "/api/users";
        $.ajax({
            url,
            method:"post",
            dataType:"json",
            data:data.field,
            success(resp){
                if (resp.success){
                    //如果添加成功,刷新表格
                    layer.msg("添加成功!")
                    setTimeout(function (){
                        parent.layui.use(["table"],function (){
                            let table = parent.layui.table;
                            table.reload('tbl');
                        });
                        let iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    },500)

                }
            },error(resp){
                console.log(resp);
            }
        });
        return false;
    });

});